package org.cent.examples.dateformat.controller;

import org.cent.examples.dateformat.dto.response.NowResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @Author Cent.Chen  2019-07-14
 * @Description Say something.
 */
@RestController
@RequestMapping("/date")
public class DateController {

    /**
     * 获取当前时间
     *
     * @return
     */
    @GetMapping("/now")
    public NowResponse now() {
        NowResponse nowResponse = new NowResponse();

        String str = "2019-01-11";
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate localDate = LocalDate.parse(str, formatter);

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date date = simpleDateFormat.parse(str);

            String format = simpleDateFormat.format(date);
            System.out.println(format);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return nowResponse;
    }
}
